package org.jeecg.modules.ws.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.aspect.annotation.AutoLog;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.ws.entity.WsBondProject;
import org.jeecg.modules.ws.entity.WsProjectSb;
import org.jeecg.modules.ws.service.IWsProjectSbService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: 债券_申报
 * @Author: jeecg-boot
 * @Date:   2025-03-27
 * @Version: V1.0
 */
@Slf4j
@Api(tags="债券_申报")
@RestController
@RequestMapping("/wsProjectSb")
public class WsProjectSbController extends JeecgController<WsProjectSb, IWsProjectSbService> {
	@Autowired
	private IWsProjectSbService wsBondSbService;

	/**
	 * 分页列表查询
	 *
	 * @param wsBondSb
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@AutoLog(value = "债券_申报-分页列表查询")
	@ApiOperation(value="债券_申报-分页列表查询", notes="债券_申报-分页列表查询")
	@GetMapping(value = "/list")
	public Result<?> queryPageList(WsProjectSb wsBondSb,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<WsProjectSb> queryWrapper = QueryGenerator.initQueryWrapper(wsBondSb, req.getParameterMap());
		Page<WsProjectSb> page = new Page<WsProjectSb>(pageNo, pageSize);
		IPage<WsProjectSb> pageList = wsBondSbService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	/**
	 * 添加
	 *
	 * @param wsBondSb
	 * @return
	 */
	@AutoLog(value = "债券_申报-添加")
	@ApiOperation(value="债券_申报-添加", notes="债券_申报-添加")
	@PostMapping(value = "/add")
	public Result<?> add(@RequestBody WsProjectSb wsBondSb) {
		wsBondSbService.save(wsBondSb);
		return Result.OK("添加成功！");
	}

	/**
	 * 编辑
	 *
	 * @param wsBondSb
	 * @return
	 */
	@AutoLog(value = "债券_申报-编辑")
	@ApiOperation(value="债券_申报-编辑", notes="债券_申报-编辑")
	@PutMapping(value = "/edit")
	public Result<?> edit(@RequestBody WsProjectSb wsBondSb) {
		wsBondSbService.updateById(wsBondSb);
		return Result.OK("编辑成功!");
	}

	 /**
	  * 新增或编辑
	  *
	  * @param wsBondSb
	  * @return
	  */
	 @AutoLog(value = "债券_申报-新增或编辑")
	 @ApiOperation(value="债券_申报-新增或编辑", notes="债券_申报-新增或编辑")
	 @PutMapping(value = "/saveOrUpdate")
	public Result<?> saveOrUpdate(@RequestBody WsProjectSb wsBondSb){
		 LambdaQueryWrapper<WsProjectSb> query = Wrappers.lambdaQuery(WsProjectSb.class);
		 query.eq(WsProjectSb::getProjectCode,wsBondSb.getProjectCode()).eq(WsProjectSb::getSqnd, wsBondSb.getSqnd());
		 wsBondSbService.saveOrUpdate(wsBondSb, query);
		 return Result.OK("新增或编辑成功!");
	}

	/**
	 * 通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "债券_申报-通过id删除")
	@ApiOperation(value="债券_申报-通过id删除", notes="债券_申报-通过id删除")
	@DeleteMapping(value = "/delete")
	public Result<?> delete(@RequestParam(name="id",required=true) String id) {
		wsBondSbService.removeById(id);
		return Result.OK("删除成功!");
	}

	/**
	 * 批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "债券_申报-批量删除")
	@ApiOperation(value="债券_申报-批量删除", notes="债券_申报-批量删除")
	@DeleteMapping(value = "/deleteBatch")
	public Result<?> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.wsBondSbService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功！");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "债券_申报-通过id查询")
	@ApiOperation(value="债券_申报-通过id查询", notes="债券_申报-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<?> queryById(@RequestParam(name="id",required=true) String id) {
		WsProjectSb wsBondSb = wsBondSbService.getById(id);
		return Result.OK(wsBondSb);
	}

	 @AutoLog(value = "债券_申报-通过ProductCode查询")
	 @ApiOperation(value="债券_申报-通过ProductCode查询", notes="债券_申报-通过ProductCode查询")
	 @GetMapping(value = "/queryByProjectCode")
	 public Result<?> queryByProjectCode(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
										 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
										 @RequestParam(name="projectCode",required=true) String projectCode) {
		 return Result.OK(wsBondSbService.queryByProductCode(pageNo,pageSize,projectCode));
	 }

	 @AutoLog(value = "债券_申报-通过ProductCode查询")
	 @ApiOperation(value="债券_申报-通过ProductCode查询", notes="债券_申报-通过ProductCode查询")
	 @GetMapping(value = "/getOneByProductIdWithThisYear")
	 public Result<?> getOneByProductIdWithThisYear(@RequestParam(name="projectCode",required=true) String projectCode) {
		 return Result.OK(wsBondSbService.getOneByProductIdWithThisYear(projectCode));
	 }

  /**
   * 导出excel
   *
   * @param request
   * @param wsBondSb
   */
  @RequestMapping(value = "/exportXls")
  public ModelAndView exportXls(HttpServletRequest request, WsProjectSb wsBondSb) {
      return super.exportXls(request, wsBondSb, WsProjectSb.class, "债券_申报");
  }

  /**
   * 通过excel导入数据
   *
   * @param request
   * @param response
   * @return
   */
  @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
  public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
      return super.importExcel(request, response, WsProjectSb.class);
  }

}
